Skip to content

pygmt.params.Position: Validate the values of cstype#4645

Open
seisman wants to merge 1 commit into
mainfrom
codex/position-cstype-validation
Open

pygmt.params.Position: Validate the values of cstype#4645
seisman wants to merge 1 commit into
mainfrom
codex/position-cstype-validation

Conversation

@seisman
Copy link
Copy Markdown
Member

@seisman seisman commented May 20, 2026

Previous behavior:

In [2]: from pygmt.params import Position

In [3]: Position((1, 0), cstype="invalid")
Out[3]: Position(refpoint=(1, 0), cstype='invalid')

Current behavior:

In [1]: from pygmt.params import Position

In [2]: Position((1, 0), cstype="invalid")
---------------------------------------------------------------------------
GMTValueError                             Traceback (most recent call last)
Cell In[2], line 1
----> 1 Position((1, 0), cstype="invalid")

File <string>:7, in __init__(self, refpoint, cstype, anchor, offset)

File ~/OSS/gmt/pygmt/pygmt/params/base.py:61, in BaseParam.__post_init__(self)
     57 def __post_init__(self):
     58     """
     59     Post-initialization method to _validate the _aliases property.
     60     """
---> 61     self._validate()

File ~/OSS/gmt/pygmt/pygmt/params/position.py:190, in Position._validate(self)
    184             raise GMTValueError(
    185                 self.refpoint,
    186                 description="reference point",
    187                 reason="Expect a valid 2-character justification code.",
    188             )
    189     case _:
--> 190         raise GMTValueError(
    191             self.cstype,
    192             description="cstype",
    193             choices=[
    194                 "mapcoords",
    195                 "plotcoords",
    196                 "boxcoords",
    197                 "inside",
    198                 "outside",
    199             ],
    200         )
    201 # Validate the anchor if specified.
    202 if self.anchor is not None and self.anchor not in _valid_anchors:

GMTValueError: Invalid cstype: 'invalid'. Expected one of: 'mapcoords', 'plotcoords', 'boxcoords', 'inside', 'outside'.

Related to #4212

@seisman seisman changed the title Validate Position cstype eagerly pygmt.params.Position: Validate the values of cstype May 20, 2026
@seisman seisman added the enhancement Improving an existing feature label May 20, 2026
@seisman seisman added this to the 0.19.0 milestone May 20, 2026
@seisman seisman added the final review call This PR requires final review and approval from a second reviewer label May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature final review call This PR requires final review and approval from a second reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant